﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.Mvc;
using MVCms.Core.Developers;
using MVCms.Core.Models;
using MVCms.Core.Services;


namespace MVCms.Web.Controllers
{
    public class SetupController : BaseController
    {
        [HttpGet]
        public ActionResult Index()
        {
            //Configuration configFile = WebConfigurationManager.OpenWebConfiguration("~");
            //AppSettingsSection AppSection = configFile.GetSection("appSettings") as AppSettingsSection;
            //AppSection.Settings["RunMigrations"].Value = "true";
            //configFile.Save();

            SystemSetupModel model = new SystemSetupModel();
            model.PortalName = "My Portal";
            model.AdminEmail = "admin@myportal.com";
            model.AdminUsername = "Administrator";
            return View(model);
        }

        [HttpPost]
        public ActionResult DoSetup(SystemSetupModel systemSetupModel)
        {
            SetupService.Start(systemSetupModel);
            System.Web.HttpRuntime.UnloadAppDomain();
            return Redirect("/");
        }
    }
}
